<template>
	<view>
		<view class="card" v-for="(order,j) in orderList" :key="j" @click="">
			<view class="flex align-center justify-between cell">
				<view class="time">下单时间：{{order.createTime}}(两小时内上门)</view>
			</view>
			<view class="flex align-center justify-between u-p-t-10">
				<view class="text999">快递单号：{{order.orderCode}}</view>
			</view>

		</view>

		<xloadmore :status="xloadmore"></xloadmore>

		<view class="flex align-center u-row-between u-p-l-32 u-p-r-32 footer">
			<view class="btn-plain" @click="handleOkxiadan()">京东快递下单</view>
		</view>
		<u-modal :show="show" title="确认京东快运下单" content='您确定要确认京东快运下单吗？' showCancelButton="true"
			@confirm="hanleYizhanJDKY()" @cancel="show=false"></u-modal>

	</view>
</template>

<script>
	import {
		getJdOrderlist,
		yizhanJDKY,
		getShopUserOrderInfoList,
	} from '@/common/api/api.js'
	export default {
		data() {
			return {
				params: {
					pageNum: 1,
					pageSize: 5,
				},
				xloadmore: "loadmore",
				show: false,
				companyId: '',
				orderList: [],
				shopOrderList: [],

			}
		},
		onShow(options) {
			this.companyId = this.$store.state.$userInfo.companyId;
			this.handleGetJdOrderlist();
		},
		mounted() {
			// 监听返回事件并刷新页面
			uni.$on('userOrderBack', this.onNavigateTo);

		},
		beforeDestroy() {
			// 移除返回事件
			uni.$off('userOrderBack', this.onNavigateTo);

		},
		methods: {
			toRoute(url) {
				uni.redirectTo({
					url: url
				})
			},
			onNavigateTo() {
				this.companyId = this.$store.state.$userInfo.companyId;
			},
			// 
			handleOkxiadan() {
				this.show = true;
			},
			// 驿站京东快递单
			hanleYizhanJDKY() {
				let search = {
					companyId: this.companyId,
					status: '3',// 已经打印小票
					orderType: '0',
					phone: '',
					time: 'time'
				}

				getShopUserOrderInfoList(search).then(res => {
					if (res.data.list.length > 0) {
						yizhanJDKY({
							companyId: this.companyId,
						}).then(res => {
							if (res.code == 200) {
								uni.$u.toast("京东快运订单下单成功！");
								this.handleGetJdOrderlist();
							}


						})
					} else {
						uni.$u.toast("店铺今日无订单，无需快递");
					}

				})
				this.show = false;
			},
			// 读取京东快递单号信息
			handleGetJdOrderlist() {
				this.xloadmore = "loading";
				getJdOrderlist({
					companyId: this.companyId,
					...this.params
				}).then(res => {
					if (this.orderList.length < res.data.total) {
						this.params.pageNum++
						res.data.list.map(e => {
							this.orderList.push(e);
						})
					}
					this.xloadmore = "nomore";
				})
			},
			onReachBottom() {
				if (this.params.pageNum != 1) {
					this.$u.throttle(this.handleGetJdOrderlist(), 300);
				}
			}
		}
	}
</script>

<style lang="scss">
	.card {
		padding: 22rpx;
		width: 686rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		margin-top: 20rpx;

		.cell {
			padding-bottom: 22rpx;
			// border-bottom: 1px solid #EEEEEE;

			.time {
				font-size: 28rpx;
				color: #999999;
			}

			.loading {
				color: #FFA42E;
			}

			.success {
				color: #0B9126;
				;
			}

			.error {
				color: #FD002B;
				;
			}

			.cancel {
				color: #FD4E00;
				;
			}
		}

		.top-border {
			border-top: 2rpx solid #EEEEEE;
		}
	}

	.btn {
		width: 120rpx;
		padding: 10rpx 20rpx;
		text-align: center;
		color: #FFFFFF;
		margin-top: 20rpx;
		background-color: #FF5B00;
		border-radius: 16rpx;
	}

	.footer {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		padding: 20rpx 0;
		background-color: #ffffff;

		.btn-plain {
			width: 190rpx;
			height: 84rpx;
			line-height: 84rpx;
			text-align: center;
			border-radius: 8rpx;
			border: 2rpx solid #FF5B00;
			font-size: 26rpx;
			color: #ffffff;
			margin-left: 486rpx;
			background-color: #FF5B00;
		}


	}
</style>